package com.zzyl.generator;

import com.zzyl.common.constant.Constants;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;

import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;

public class VelocityTest {

    public static void main(String[] args) throws IOException {
        Properties p = new Properties();
        // 加载classpath目录下的vm文件
        p.setProperty("resource.loader.file.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
        // 定义字符集
        p.setProperty(Velocity.INPUT_ENCODING, Constants.UTF8);
        // 初始化Velocity引擎，指定配置Properties
        Velocity.init(p);

        //1、准备模板数据
        VelocityContext context = new VelocityContext();
        context.put("message","加油少年！");

        //2、加载模板
        Template template = Velocity.getTemplate("vms/index.html.vm");

        //3、合成输出文件
        FileWriter fileWriter = new FileWriter("D:/java177.html");
        template.merge(context,fileWriter);
        fileWriter.close();
    }
}
